<template>
    <div>
        <el-dialog
            :title="$t('device-edit-install-1')"
            :visible="visibleEdit"
            class="el-dialog-sm"
            @close="()=>{$store.commit('setVisibleEdit',false)}">
            <el-form ref="form" :model="form" label-width="200px" >
                <el-row :gutter="24">
                    <el-col :span="20">
                        <el-form-item :label="$t('pageNumber')" prop="actionStep" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input-number v-model="form.actionStep" controls-position="right" placeholder="" :min="1"></el-input-number>
                        </el-form-item>
                        <el-form-item :label="$t('pushNews.title')" prop="title" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-model="form.title" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item :label="$t('device-video-url')" prop="videoUrl" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-model="form.videoUrl" placeholder=""></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setVisibleEdit',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('save')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components:{
    },
    props: {
        snGuideId:'',
        editStepData:''
    },
    data() {
        return {
            form:{
                id:'',
                snGuideId:'',
                actionStep:'',
                title:'',
                videoUrl:'',
            }
        };
    },
    computed: {
        visibleEdit(){
            return this.$store.state.sysStore.visibleEdit
        }
    },
    watch:{
        editStepData:{
            handler(nv,ov){
                if(nv){
                    for(let key in this.form){
                        this.form[key]=nv[key]
                    }
                    this.form.id=nv.sid
                }
            }
        }
    },
    mounted(){
      
    },
    methods: {
        changeType(val){
            this.typeData=this.typeDataObj[val]
            this.form.inverterType=''
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                this.commitForm()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
        async commitForm(){
            this.form.snGuideId=this.snGuideId
            let res = await this.API.editSteps(this.form)
            if(res.success){
                this.$message.success(this.$t('index.control_success'));
            }else{
                this.$message.error(this.$t('index.control_fail'));
            }
            this.$store.commit('setVisibleEdit',false)
            this.$emit('uploadPage',true)
        }
    }
};
</script>

<style  lang="less">
</style>
